<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {

    //原始顶级子集文件
    private $toplist_file = "./Org/Data/Original_top_list.json";
    private $subitem_file = "./Org/Data/init_subitem.json";
    private $submodel_file = "./Org/Data/Original_name_submodel.json";
    private $dic_file = "./Org/Data/init_dic.json";
    private $city_file = "./Org/Data/Original_City.json";
    private $province_file = "./Org/Data/Original_Province.json";
    private $sj_zd_file = "./Org/Data/tree.json";
    private $corpid = 'wx354598b372f7261a';

    public function index(){
           //33个子集项
           $toplist = json_decode(file_get_contents($this->toplist_file),true);
           //一个员工所有的子集和字段
           $subitem = json_decode(file_get_contents($this->subitem_file),true);
           //去掉information和uuid的员工所有子集和字段
           $submodel = json_decode(file_get_contents($this->submodel_file),true);
           //所有字典数据
           $dic = json_decode(file_get_contents($this->dic_file),true);
           //城市字典
           $city = json_decode(file_get_contents($this->city_file),true);
           //省份字典
           $province = json_decode(file_get_contents($this->province_file),true);
            //时间字段验证
           $sj = json_decode(file_get_contents($this->sj_zd_file),true);
           $file = ($subitem['information']);
        $arr = [];
	    //dump($sj);
        dump($dic);exit;
        foreach($dic['CASC.HR.DICT.ALL'] as $k=>$v){
            if($v['layer']){
                $arr[$k] = $v;
            }
        }
        //dump($arr);exit;
        foreach($arr as $k=>$v){
            $data[$k] = $this->getTree($v['subitem']);
        }
        //dump($data);exit;
        file_put_contents('./Org/tree.json',json_encode($data));
        exit;
       $data = file_get_contents('./Org/a.json');
       $_data = json_decode($data,true)['information'];
//       dump($_data);exit;
//       file_put_contents($this->subitem_file,$data);
//       file_put_contents($this->submodel_file,json_encode($_data));
//       dump(json_decode(file_get_contents('./Org/a.json'),true));exit;
       $file = "./Org/Data/UserData/top_sort/".$this -> corpid.'.conf';
       //dump(json_decode($file,true));exit;
        $aa = ((file_get_contents('./Org/a.json')));



    }
    private function initTopList($data){
        //$data = $data['information'];
        //初始化数据缓冲区
        $buffer = [];
        foreach($data as $k => $v){
            $buffer[$k]['caption'] = $v['caption'];
            $buffer[$k]['name'] = $k;
        }
        file_put_contents($this->toplist_file,json_encode($buffer));
        return $buffer;
    }

    private function getTree($arr,$parent_id='',$lev=1){
        $list = [];
        foreach($arr as $k=>$v){
            if($v['mainid'] == $parent_id){
                $v['lev'] = $lev;
                $list[] = $v;
                $list = array_merge($list,$this->getTree($arr,$v['value'],$lev+1));
            }
        }
        return $list;
    }

    private function bbb($arr,$parent_id=''){
        $list = [];
        foreach($arr as $k=>$v){
            if($v['mainid'] == $parent_id){
                $list[$k]['name'] = $v['caption'];
                $list[$k]['value'] = $v['value'];
                $children = $this->bbb($arr,$v['value']);
                $list[$k]['children'] = $children;
            }
        }
        return $list;
    }

    public function aaa(){
        $arr = [
            0 => [
                'name' => '河北省',
                'icon' => 'p_src',
                'children' => [
                    0 => [
                        'name' => '石家庄',
                        'icon' => 'p_src',
                        'children' => []
                    ],
                    1 => [
                        'name' => '保定',
                        'icon' => 'p_src',
                        'children' => []
                    ],
                    2 => [
                        'name' => '邯郸',
                        'icon' => 'p_src',
                        'children' => []
                    ],
                    3 => [
                        'name' => '承德',
                        'icon' => 'p_src',
                        'children' => []
                    ]
                ]
            ]
        ];
        dump(json_encode($arr));
    }

    public function upfile(){

        $str = 'BO_CASC_HR_YGRS,ZP,FJ;;BO_CASC_HR_ZYJSZWZGXX,0,FJ;;BO_CASC_HR_ZYJSZWZGXX,0,FJ;;
        BO_CASC_HR_XLJXWXX,0,FJ1';
        $arr = [
            0 => [
                'ZP' => [
                    'ThinkPHP.jpg' => [
                        'href' => 'c:/www/renli/public/uploads/ThinkPHP.jpg',
                        'status' => 1
                    ],
                    'ThinkPHP1.jpg' => [
                        'href' => 'c:/www/renli/public/uploas/ThinkPHP1.jpg',
                        'status' => 1
                    ],
                ],
                'FJ' => [

                ]
            ],
        ];


















        if(!IS_POST){
            $this->display();
        }else{

            $upload = new \Think\Upload();// 实例化上传类
            $upload->maxSize  = 3145728;
            $upload->rootPath = './Public';
            $upload->savePath = '/Uploads/';
            $upload->saveName = '';
            $upload->exts     = array('jpg', 'gif', 'png', 'jpeg','docx');
            $upload->autoSub  = true;
            $upload->subName  = '9999002122';
            $info = $upload->upload();
            dump($info);

        }
    }
}
